﻿using System;
using Microsoft.Practices.Unity;
using RAD.Modules.UI.Interfaces;

namespace RAD.Modules.UI.Views
{
    public class MainToolBarPresenter : IMainToolBarPresenter
    {
        private IUnityContainer _container;
        private IToolbarController _controller;

        public IMainToolBar View
        {
            get;
            set;
        }

        public IToolbarController Controller
        {
            get;
            set;
        }

        public MainToolBarPresenter(IMainToolBar view, IUnityContainer container)
        {
            View = view;
            View.AboutViewShow += new EventHandler<EventArgs>(View_AboutViewShow);
            View.ApplicationClose += new EventHandler<EventArgs>(View_ApplicationExit);
            _container = container;

            _controller = _container.Resolve<IToolbarController>();
            _controller.Run();
        }

        /// <summary>
        /// Показываем диалог о программе. Запросы перенаправляем на контролллер.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void View_AboutViewShow(object sender, EventArgs e)
        {
            _controller.AboutViewShow("");
        }

        /// <summary>
        /// Выход из приложения
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void View_ApplicationExit(object sender, EventArgs e)
        {
            _controller.ApplicationExit();
        }
    }
}